package iewShopApp.namespace;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;


public class IewShopAppActivity extends PreferenceActivity implements OnClickListener {
	private Button HaasMillButton;
	private Button HaasLatheButton;
	private Button BridgeportMillButton;
	private Button ManualMillButton;
	private Button ManualLatheButton;
	private Button WhereButton;
	private ImageButton HomeButton;
	private ImageButton LearningHomeButton;
	private Button MainLearningButton;
	private Button MainTapButton;
	private Button MainDrillButton;
	private Button MainLatheButton;
	private Button MainReamButton;
	private Button MainMillButton;
	private Button CalcLaunchButton;
	private Button PrefLaunchButton;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState); 
		addPreferencesFromResource(R.xml.preferences);
		setContentView(R.layout.main);
		
//		MainLearningButton = (Button) findViewById(R.id.MainLearning);
//		MainLearningButton.setOnClickListener(this);
//
//		MainTapButton = (Button) findViewById(R.id.MainTap);
//		MainTapButton.setOnClickListener(this);
//
//		MainDrillButton = (Button) findViewById(R.id.MainDrill);
//		MainDrillButton.setOnClickListener(this);
//
//		MainLatheButton = (Button) findViewById(R.id.MainLathe);
//		MainLatheButton.setOnClickListener(this);
//
//		MainReamButton = (Button) findViewById(R.id.MainReam);
//		MainReamButton.setOnClickListener(this);
//
//		MainMillButton = (Button) findViewById(R.id.MainMill);
//		MainMillButton.setOnClickListener(this);
		 defineMainButtons();
	}


	/*
	 * Resources res = getResources(); // Resource object to get Drawables
	 * TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec
	 * spec; // Resusable TabSpec for each tab
	 * 
	 * 
	 * // Create an Intent to launch an Activity for the tab (to be reused)
	 * intent = new Intent().setClass(this, HaasMillActivity.class);
	 * 
	 * // Initialize a TabSpec for each tab and add it to the TabHost spec =
	 * tabHost.newTabSpec("haasmill").setIndicator("HaasCNCmill",
	 * res.getDrawable(R.drawable.tab_haas_mill)) .setContent(intent);
	 * tabHost.addTab(spec);
	 * 
	 * // Do the same for the other tabs intent = new Intent().setClass(this,
	 * bridgeportActivity.class); spec =
	 * tabHost.newTabSpec("bridgeport").setIndicator("Bridgeport",
	 * res.getDrawable(R.drawable.tab_bridgeport_mill)) .setContent(intent);
	 * tabHost.addTab(spec);
	 * 
	 * intent = new Intent().setClass(this, HaasLatheActivity.class); spec =
	 * tabHost.newTabSpec("haaslathe").setIndicator("HaasLathe",
	 * res.getDrawable(R.drawable.tab_haas_lathe)) .setContent(intent);
	 * tabHost.addTab(spec);
	 * 
	 * tabHost.setCurrentTab(2);
	 */

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.textMill:
			setContentView(R.layout.mill);
			addListenerOnButton7();
			break;
		case R.id.textDrill:
			Intent myIntent1 = new Intent().setClass(this, DrillActivity.class);
			startActivity(myIntent1);
			break;
		case R.id.textLathe:
			setContentView(R.layout.lathe);
			addListenerOnButton7();
			break;
		case R.id.textReam:
			setContentView(R.layout.ream);
			addListenerOnButton7();
			break;
		case R.id.textTap:
			Intent myIntent2 = new Intent().setClass(this, TapActivity.class);
			startActivity(myIntent2);
			break;
		case R.id.textLearning:
			// trial = new LearningActivity();
			// trial.update();
			setContentView(R.layout.learning);
			defineLearningButtons();
//			addListenerOnButton();
//			addListenerOnButton2();
//			addListenerOnButton3();
//			addListenerOnButton4();
//			addListenerOnButton5();
//			addListenerOnButton6();
			addListenerOnButton7();
			break;

		}
		return true;
	}

//	public void addListenerOnButton() {
//		HaasMillButton = (ImageButton) findViewById(R.id.HaasMillClick);
//		HaasMillButton.setOnClickListener(new OnClickListener() {
//
//			// @Override
//			public void onClick(View arg0) {
//				setContentView(R.layout.haas_mill_learning);
//				addListenerOnButton7();
//				addListenerOnButton8();
//			}
//		});
//	}
//
//	public void addListenerOnButton2() {
//		HaasLatheButton = (ImageButton) findViewById(R.id.HaasLatheClick);
//		HaasLatheButton.setOnClickListener(new OnClickListener() {
//
//			// @Override
//			public void onClick(View arg0) {
//				setContentView(R.layout.haas_lathe_learning);
//				addListenerOnButton7();
//				addListenerOnButton8();
//			}
//		});
//	}
//
//	public void addListenerOnButton3() {
//		ManualMillButton = (ImageButton) findViewById(R.id.ManualMillClick);
//		ManualMillButton.setOnClickListener(new OnClickListener() {
//
//			// @Override
//			public void onClick(View arg0) {
//				setContentView(R.layout.manual_mill_learning);
//				addListenerOnButton7();
//				addListenerOnButton8();
//			}
//		});
//	}
//
//	public void addListenerOnButton4() {
//		ManualLatheButton = (ImageButton) findViewById(R.id.ManualLatheClick);
//		ManualLatheButton.setOnClickListener(new OnClickListener() {
//
//			// @Override
//			public void onClick(View arg0) {
//				setContentView(R.layout.manual_lathe_learning);
//				addListenerOnButton7();
//				addListenerOnButton8();
//			}
//		});
//	}
//
//	public void addListenerOnButton5() {
//		WhereButton = (ImageButton) findViewById(R.id.WhereClick);
//		WhereButton.setOnClickListener(new OnClickListener() {
//
//			// @Override
//			public void onClick(View arg0) {
//				setContentView(R.layout.where_learning);
//				addListenerOnButton7();
//				addListenerOnButton8();
//			}
//		});
//	}
//
//	public void addListenerOnButton6() {
//		BridgeportMillButton = (ImageButton) findViewById(R.id.BridgeportMillClick);
//		BridgeportMillButton.setOnClickListener(new OnClickListener() {
//			// @Override
//			public void onClick(View arg0) {
//				setContentView(R.layout.bridgeport_mill_learning);
//				addListenerOnButton7();
//				addListenerOnButton8();
//			}
//		});
//	}

	public void addListenerOnButton7() {
		HomeButton = (ImageButton) findViewById(R.id.HomeClick);
		HomeButton.setOnClickListener(new OnClickListener() {

			// @Override
			public void onClick(View arg0) {
				setContentView(R.layout.main);
				 defineMainButtons();
			}
		});
	}

	public void addListenerOnButton8() {
		LearningHomeButton = (ImageButton) findViewById(R.id.LearningHome);
		LearningHomeButton.setOnClickListener(new OnClickListener() {

			// @Override
			public void onClick(View arg0) {
				setContentView(R.layout.learning);
//				addListenerOnButton();
//				addListenerOnButton2();
//				addListenerOnButton3();
//				addListenerOnButton4();
//				addListenerOnButton5();
//				addListenerOnButton6();
				addListenerOnButton7();
				defineLearningButtons();
			}
		});
	}

	// public void onClick(View v) {
	// // TODO Auto-generated method stub
	//
	// }

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.MainLearning:
			setContentView(R.layout.learning);
//			addListenerOnButton();
//			addListenerOnButton2();
//			addListenerOnButton3();
//			addListenerOnButton4();
//			addListenerOnButton5();
//			addListenerOnButton6();
			defineLearningButtons();
			addListenerOnButton7();
			break;
		case R.id.MainDrill:
			setContentView(R.layout.drill);
//			addListenerOnButton7();
			Intent myIntent1 = new Intent().setClass(this, DrillActivity.class);
			startActivity(myIntent1);
            setContentView(R.layout.main);
            defineMainButtons();
			break;
		case R.id.MainLathe:
			setContentView(R.layout.lathe);
			addListenerOnButton7();
			break;
		case R.id.MainMill:
			setContentView(R.layout.mill);
			addListenerOnButton7();
			break;
		case R.id.MainReam:
			setContentView(R.layout.ream);
			addListenerOnButton7();
			break;
		case R.id.MainTap:
			setContentView(R.layout.tap_main);
			Intent myIntent2 = new Intent().setClass(this, TapActivity.class);
			startActivity(myIntent2);
            setContentView(R.layout.main);
            defineMainButtons();
			break;
			
		case R.id.CalcButton:
			setContentView(R.layout.calc_main); 
			Intent myIntent = new Intent().setClass(this, Calculator.class);
			startActivity(myIntent);
            setContentView(R.layout.main);
            defineMainButtons();
            break;
            
		case R.id.PrefButton:
//			setContentView(R.xml.preferences); 
			Intent myIntent3 = new Intent().setClass(this, AppPreferences.class);
			startActivity(myIntent3);
            setContentView(R.layout.main);
            defineMainButtons();
            break;
    // Resources res = getResources();
    // res.getDrawable(R.layout.calc_main);
    // res.setContent(myIntent);
    case R.id.BridgeportMillClick:
            setContentView(R.layout.bridgeport_mill_learning);
            addListenerOnButton7();
            addListenerOnButton8();
            break;
    // addListenerOnButton8();
    case R.id.HaasMillClick:
            setContentView(R.layout.haas_mill_learning);
            addListenerOnButton7();
            addListenerOnButton8();
            break;
    case R.id.HaasLatheClick:
            setContentView(R.layout.haas_lathe_learning);
            addListenerOnButton7();
            addListenerOnButton8();
            break;
    case R.id.ManualMillClick:
            setContentView(R.layout.manual_mill_learning);
            addListenerOnButton7();
            addListenerOnButton8();
            break;
    case R.id.ManualLatheClick:
            setContentView(R.layout.manual_lathe_learning);
            addListenerOnButton7();
            addListenerOnButton8();
            break;
    case R.id.WhereClick:
            setContentView(R.layout.where_learning);
            addListenerOnButton7();
            addListenerOnButton8();
            break;
		}
	}

	public void defineMainButtons() {
		MainLearningButton = (Button) findViewById(R.id.MainLearning);
		MainLearningButton.setOnClickListener(this);

		MainTapButton = (Button) findViewById(R.id.MainTap);
		MainTapButton.setOnClickListener(this);

		MainDrillButton = (Button) findViewById(R.id.MainDrill);
		MainDrillButton.setOnClickListener(this);

		MainLatheButton = (Button) findViewById(R.id.MainLathe);
		MainLatheButton.setOnClickListener(this);

		MainReamButton = (Button) findViewById(R.id.MainReam);
		MainReamButton.setOnClickListener(this);

		MainMillButton = (Button) findViewById(R.id.MainMill);
		MainMillButton.setOnClickListener(this);
//		
		CalcLaunchButton = (Button) findViewById(R.id.CalcButton);
		CalcLaunchButton.setOnClickListener(this);
		
		PrefLaunchButton = (Button) findViewById(R.id.PrefButton);
		PrefLaunchButton.setOnClickListener(this);
	}

    public void defineLearningButtons() {
        BridgeportMillButton = (Button) findViewById(R.id.BridgeportMillClick);
        BridgeportMillButton.setOnClickListener(this);

        HaasMillButton = (Button) findViewById(R.id.HaasMillClick);
        HaasMillButton.setOnClickListener(this);

        HaasLatheButton = (Button) findViewById(R.id.HaasLatheClick);
        HaasLatheButton.setOnClickListener(this);

        ManualMillButton = (Button) findViewById(R.id.ManualMillClick);
        ManualMillButton.setOnClickListener(this);

        ManualLatheButton = (Button) findViewById(R.id.ManualLatheClick);
        ManualLatheButton.setOnClickListener(this);

        WhereButton = (Button) findViewById(R.id.WhereClick);
        WhereButton.setOnClickListener(this);
    }
	// public void LearningHaas(View v){
	// //int counter = 0;
	// //blinkLED2(counter);
	//
	// if(HaasButton.isChecked()){
	// setContentView(R.layout.haas_learning) // button says on, light is off
	// //buttonLED.setText(R.string.on);}
	// }
	// // else{
	// // buffer[0]=(byte)1; // button says off, light is on
	// // //buttonLED.setText(R.string.off);}
	// // }
	//
	// }
	// public void onClick(DialogInterface arg0, int arg1) {
	// // TODO Auto-generated method stub
	//
}